package com.nbsaas.boot.app.rest.convert;

import com.nbsaas.boot.app.api.domain.response.AppUserRoleResponse;
import com.nbsaas.boot.app.data.entity.AppUserRole;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 应用用户角色-实体对象转化成响应对象
 */

public class AppUserRoleResponseConvert implements Converter<AppUserRoleResponse, AppUserRole> {

    @Override
    public AppUserRoleResponse convert(AppUserRole source) {
        AppUserRoleResponse result = new AppUserRoleResponse();
        BeanDataUtils.copyProperties(source, result);
        if (source.getApp() != null) {
            result.setApp(source.getApp().getId());
        }
        if (source.getRole() != null) {
            result.setRole(source.getRole().getId());
        }

        try {
            if (source.getApp() != null) {
                result.setAppName(source.getApp().getName());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getRole() != null) {
                result.setRoleName(source.getRole().getName());
            }
        } catch (Exception ignored) {
        }

        return result;
    }

}

